package com.ktgj.pay.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.pay.domain.PayType;
import com.ktgj.pay.service.IPayTypeService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 支付类型Controller
 * 
 * @author ruoyi
 * @date 2022-01-08
 */
@RestController
@RequestMapping("/type")
public class PayTypeController extends BaseController
{
    @Autowired
    private IPayTypeService payTypeService;

    /**
     * 查询支付类型列表
     */
    @PreAuthorize(hasPermi = "pay:type:list")
    @GetMapping("/list")
    public TableDataInfo list(PayType payType)
    {
        startPage();
        List<PayType> list = payTypeService.selectPayTypeList(payType);
        return getDataTable(list);
    }

    /**
     * 导出支付类型列表
     */
    @PreAuthorize(hasPermi = "pay:type:export")
    @Log(title = "支付类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PayType payType) throws IOException
    {
        List<PayType> list = payTypeService.selectPayTypeList(payType);
        ExcelUtil<PayType> util = new ExcelUtil<PayType>(PayType.class);
        util.exportExcel(response, list, "支付类型数据");
    }

    /**
     * 获取支付类型详细信息
     */
    @PreAuthorize(hasPermi = "pay:type:query")
    @GetMapping(value = "/{payId}")
    public AjaxResult getInfo(@PathVariable("payId") Long payId)
    {
        return AjaxResult.success(payTypeService.selectPayTypeById(payId));
    }

    /**
     * 新增支付类型
     */
    @PreAuthorize(hasPermi = "pay:type:add")
    @Log(title = "支付类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PayType payType)
    {
        return toAjax(payTypeService.insertPayType(payType));
    }

    /**
     * 修改支付类型
     */
    @PreAuthorize(hasPermi = "pay:type:edit")
    @Log(title = "支付类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PayType payType)
    {
        return toAjax(payTypeService.updatePayType(payType));
    }

    /**
     * 删除支付类型
     */
    @PreAuthorize(hasPermi = "pay:type:remove")
    @Log(title = "支付类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{payIds}")
    public AjaxResult remove(@PathVariable Long[] payIds)
    {
        return toAjax(payTypeService.deletePayTypeByIds(payIds));
    }

//    /**
//     * 根据业务类型查询支付方式
//     * @return
//     */
//    @PostMapping("/queryPayType")
//    public List<PayType> queryPayType(@RequestBody Map<String, Object> map) {
//        if (map.get("businessType") != null && !map.get("businessType").equals("")){
//            String businessType = map.get("businessType").toString();
//            List<PayType> payBusinesses = payTypeService.queryPayType(businessType);
//            return payBusinesses;
//        }
//        else {
//            return null;
//        }
//    }

    /**
     * 根据业务类型查询支付方式
     * @param businessType
     * @return
     */
    @PostMapping("/queryPayType")
    public List<PayType> queryPayType(@RequestParam("businessType") String businessType) {
        List<PayType> payBusinesses = payTypeService.queryPayType(businessType);
        return payBusinesses;
    }
}
